package xrz.com.jr;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

import myhttps.Http;
import myhttps.HttpConst;
import myhttps.HttpListener;
import xrz.com.jr.adapter.Adapter_Kefu;
import xrz.com.jr.entity.KeFu;
import xrz.com.jr.utils.BaseDialog;
import xrz.com.jr.utils.ExitUtil;

public class KeFuActivity extends AppCompatActivity {
    private ListView mListView;
    private Adapter_Kefu adapter;
    private List<KeFu> datas = new ArrayList<KeFu>();
    private TextView Tv_Title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_base);
        init();
        ExitUtil.getInstant().addToPool(this);
    }

    private void init() {
        mListView = (ListView) findViewById(R.id.listview);
        Tv_Title = (TextView) findViewById(R.id.top_tv);
        Tv_Title.setText("售后客服");
        adapter = new Adapter_Kefu(this);
        mListView.setAdapter(adapter);
        Http.getInstant().sendRequest(this, HttpConst.getKeFu, null, new HttpListener() {
            @Override
            public void onHttpSuccess(String result) {
                datas = JSON.parseArray(result, KeFu.class);
                adapter.addAll(datas);
            }

            @Override
            public void onHttpError(String error) {

            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            BaseDialog.showDialog(KeFuActivity.this, new BaseDialog.onDialogBtnClickListener() {
                @Override
                public void onClick() {
                    ExitUtil.getInstant().exitApp(KeFuActivity.this);
                }
            });
        }
        return super.onKeyDown(keyCode, event);
    }
}
